package com.fruitshop.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fruitshop.service.FruitService;
import com.fruitshop.vo.FruitVO;
import com.fruitshop.vo.ResultVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 水果控制器
 */
@Slf4j
@RestController
@RequestMapping("/fruit")
@RequiredArgsConstructor
public class FruitController {
    
    private final FruitService fruitService;
    
    /**
     * 分页查询水果列表
     *
     * @param page       页码
     * @param pageSize   页大小
     * @param categoryId 分类ID
     * @param keyword    关键词
     * @return 水果分页列表
     */
    @GetMapping("/list")
    public ResultVO<Page<FruitVO>> list(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) Long categoryId,
            @RequestParam(required = false) String keyword) {
        Page<FruitVO> fruitPage = fruitService.pageList(page, pageSize, categoryId, keyword);
        return ResultVO.success(fruitPage);
    }
    
    /**
     * 获取水果详情
     *
     * @param id 水果ID
     * @return 水果详情
     */
    @GetMapping("/detail/{id}")
    public ResultVO<FruitVO> detail(@PathVariable Long id) {
        FruitVO fruitVO = fruitService.getDetail(id);
        return ResultVO.success(fruitVO);
    }
    
    /**
     * 获取热门水果列表
     *
     * @param limit 限制数量
     * @return 热门水果列表
     */
    @GetMapping("/hot")
    public ResultVO<List<FruitVO>> hot(@RequestParam(defaultValue = "6") Integer limit) {
        List<FruitVO> hotFruits = fruitService.listHotFruits(limit);
        return ResultVO.success(hotFruits);
    }
    
    /**
     * 获取推荐水果列表
     *
     * @param limit 限制数量
     * @return 推荐水果列表
     */
    @GetMapping("/recommend")
    public ResultVO<List<FruitVO>> recommend(@RequestParam(defaultValue = "6") Integer limit) {
        List<FruitVO> recommendFruits = fruitService.listRecommendFruits(limit);
        return ResultVO.success(recommendFruits);
    }
} 